import React, { useRef } from 'react';
interface IProps {
    id?: string;
    src: string;
    height?: number;
}
export default React.memo((props: IProps) => {
    const iframeRef = useRef<HTMLIFrameElement>(null)
    const onLoad = () => {
        const iframe = iframeRef.current
        if (iframe === null || props.height) return
        iframe.style.height = 'auto'
        setTimeout(() => {
            /** 自适应不支持从大到小的高度变化 */
            iframe.style.height = iframe.contentDocument?.body.scrollHeight + 'px'
        })
    }
    return (
        <iframe height={props.height} ref={iframeRef} id={props.id} src={props.src} frameBorder="0" width="100%" onLoad={onLoad} />
    )
})